]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st/icon: Add API to set the fallback GIcon
authorJonas Dreßler <verdre@v0yd.nl>
Thu, 21 Nov 2019 10:03:22 +0000 (17:03 +0700)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 13 Jan 2020 13:44:08 +0000 (14:44 +0100)
Let's support the fallback icon a bit better and allow setting its GIcon
just as we do for the normal icon.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/888

src/st/st-icon.c
src/st/st-icon.h

index 6cc7e4dbad72377b4f48437b0afd0b449d133cc7..13f7dd54ffe592c9829a0fdef1b6e6e155bbf144 100644 (file)
@@ -37,6 +37,8 @@ enum
   PROP_0,
 
   PROP_GICON,
+  PROP_FALLBACK_GICON,
+
   PROP_ICON_NAME,
   PROP_ICON_SIZE,
   PROP_FALLBACK_ICON_NAME,
@@ -86,6 +88,10 @@ st_icon_set_property (GObject      *gobject,
       st_icon_set_gicon (icon, g_value_get_object (value));
       break;
 
+    case PROP_FALLBACK_GICON:
+      st_icon_set_fallback_gicon (icon, g_value_get_object (value));
+      break;
+
     case PROP_ICON_NAME:
       st_icon_set_icon_name (icon, g_value_get_string (value));
       break;
@@ -118,6 +124,10 @@ st_icon_get_property (GObject    *gobject,
       g_value_set_object (value, st_icon_get_gicon (icon));
       break;
 
+    case PROP_FALLBACK_GICON:
+      g_value_set_object (value, st_icon_get_fallback_gicon (icon));
+      break;
+
     case PROP_ICON_NAME:
       g_value_set_string (value, st_icon_get_icon_name (icon));
       break;
@@ -246,6 +256,13 @@ st_icon_class_init (StIconClass *klass)
                          G_TYPE_ICON,
                          ST_PARAM_READWRITE);
 
+  props[PROP_FALLBACK_GICON] =
+    g_param_spec_object ("fallback-gicon",
+                         "Fallback GIcon",
+                         "The fallback GIcon shown if the normal icon fails to load",
+                         G_TYPE_ICON,
+                         ST_PARAM_READWRITE);
+
   props[PROP_ICON_NAME] =
     g_param_spec_string ("icon-name",
                          "Icon name",
@@ -601,6 +618,47 @@ st_icon_set_gicon (StIcon *icon, GIcon *gicon)
   st_icon_update (icon);
 }
 
+/**
+ * st_icon_get_fallback_gicon:
+ * @icon: a #StIcon
+ *
+ * Gets the currently set fallback #GIcon.
+ *
+ * Returns: (transfer none): The fallback #GIcon, if set, otherwise %NULL
+ */
+GIcon *
+st_icon_get_fallback_gicon (StIcon *icon)
+{
+  g_return_val_if_fail (ST_IS_ICON (icon), NULL);
+
+  return icon->priv->fallback_gicon;
+}
+
+/**
+ * st_icon_set_fallback_gicon:
+ * @icon: a #StIcon
+ * @fallback_gicon: (nullable): the fallback #GIcon
+ *
+ * Sets a fallback #GIcon to show if the normal icon fails to load.
+ * If @fallback_gicon is %NULL or fails to load, the icon is unset and no
+ * texture will be visible for the fallback icon.
+ */
+void
+st_icon_set_fallback_gicon (StIcon *icon,
+                            GIcon  *fallback_gicon)
+{
+  g_return_if_fail (ST_IS_ICON (icon));
+  g_return_if_fail (fallback_gicon == NULL || G_IS_ICON (fallback_gicon));
+
+  if (g_icon_equal (icon->priv->fallback_gicon, fallback_gicon))
+    return;
+
+  g_set_object (&icon->priv->fallback_gicon, fallback_gicon);
+  g_object_notify_by_pspec (G_OBJECT (icon), props[PROP_FALLBACK_GICON]);
+
+  st_icon_update (icon);
+}
+
 /**
  * st_icon_get_icon_size:
  * @icon: an #StIcon
index f510520dc23919a6c8ec0cac7ae40b564377f523..8714ef931cbc3088408b38a04a6c082bcf4c106f 100644 (file)
@@ -60,6 +60,10 @@ GIcon       *st_icon_get_gicon (StIcon *icon);
 void         st_icon_set_gicon (StIcon *icon,
                                 GIcon  *gicon);
 
+GIcon       *st_icon_get_fallback_gicon (StIcon *icon);
+void         st_icon_set_fallback_gicon (StIcon *icon,
+                                         GIcon  *fallback_gicon);
+
 const gchar *st_icon_get_icon_name (StIcon      *icon);
 void         st_icon_set_icon_name (StIcon      *icon,
                                     const gchar *icon_name);